package com.itrip.controller;

import com.itrip.document.Hotel;
import com.itrip.dto.HotelRoomDTO;
import com.itrip.dto.ResponseDTO;
import com.itrip.service.HotelService;
import com.itrip.vo.hotel.HotelVO;
import com.itrip.vo.room.RoomVO;
import io.swagger.annotations.*;
import org.apache.solr.client.solrj.SolrServerException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;

@Api(tags = "酒店相关接口")
@ApiResponses({
        @ApiResponse(code = 200, message = "请求正常", response = ResponseDTO.class)
})

@RestController
public class HotelController {

    @Resource
    private HotelService hotelService;

    @ApiOperation("条件查询酒店房间列表")
    @ApiImplicitParam(name = "hotelName",value = "酒店名称", required = true)
    @GetMapping("/getQueryHotelRoomList")  
    public ResponseDTO getQueryHotelRoomList(@RequestParam String hotelName){
        List<HotelRoomDTO> hotelRoomDTO  = hotelService.getQueryHotelRoomList(hotelName);

        return new ResponseDTO(100,"查询酒店房间列表成功",hotelRoomDTO);
    }

    @ApiOperation("查询酒店房间列表")
    @ApiImplicitParam(name = "id",value = "酒店ID", required = true)
    @GetMapping("/getHotelRoomList")
    public ResponseDTO getHotelRoomList(@RequestParam Integer id){

        HotelRoomDTO hotelRoomDTO = hotelService.getHotelRoomList(id);

        return new ResponseDTO(100,"查询酒店房间列表成功",hotelRoomDTO);

    }


                                 @ApiOperation("查询酒店数量")
                                 @ApiImplicitParam(name = "keyword",value = "关键词")
                                 @GetMapping("/getHotelCount")
    public ResponseDTO getHotelCount(HotelVO hotelVO) throws IOException, SolrServerException {
        long count = hotelService.getHotelCount(hotelVO);

        return new ResponseDTO(100,"查询酒店数量成功",count);
    }

    @ApiOperation("查询酒店列表接口")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "keyword",value = "关键词"),
            @ApiImplicitParam(name = "pageNow",value = "页码", required = true),
            @ApiImplicitParam(name = "pageSize",value = "显示行数", required = true),
    })

    @GetMapping("/getHotelByQuery")
    public ResponseDTO getHotelByQuery(HotelVO hotelVO, Integer pageNow, Integer pageSize) throws IOException, SolrServerException {
        List<Hotel> hotelRoomDTO = hotelService.getHotelByQuery(hotelVO, pageNow, pageSize);

        return new ResponseDTO(100,"查询酒店列表接口",hotelRoomDTO);
    }
}
